<template>
  <div>
    <el-dialog @close="changeAddition" v-model="dialogState" title="添加员工信息">
      <!-- 新增员工表单 -->
      <el-form :inline="true" :model="form">
        <el-form-item label="* 姓名" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"/>
        </el-form-item>
        <el-form-item label="* 性别" :label-width="formLabelWidth">
          <el-radio-group v-model="form.sex">
            <el-radio label="男"/>
            <el-radio label="女"/>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="* 手机号码" :label-width="formLabelWidth">
          <el-input v-model="form.phone" autocomplete="off"/>
        </el-form-item>
        <el-form-item label="* 证件号码" :label-width="formLabelWidth">
          <el-input v-model="form.id" autocomplete="off"/>
        </el-form-item>
        <el-form-item label="* 部门" :label-width="dropLabelWidth">
          <el-select v-model="form.dept" placeholder="请选择部门">
            <el-option v-for="item in depts" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="* 岗位" :label-width="formLabelWidth">
          <el-input v-model="form.post" autocomplete="off"/>
        </el-form-item>
        <el-form-item label="* 状态" :label-width="dropLabelWidth">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option v-for="item in statusList" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="* 入职时间" :label-width="formLabelWidth">
          <div class="block">
            <el-date-picker v-model="form.entryDate"
                            type="date"
                            value-format="YYYY-MM-DD"
                            placeholder="选择入职日期">
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item label="出生日期" :label-width="formLabelWidth">
          <div class="block">
            <el-date-picker v-model="form.birth"
                            type="date"
                            value-format="YYYY-MM-DD"
                            placeholder="选择出生日期">
            </el-date-picker>
          </div>
        </el-form-item>
      </el-form>
      <!-- 表单尾部取消和确认按钮 -->
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="changeAddition">取消</el-button>
          <el-button type="primary" @click="confirm">确认</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
  import { ElMessage } from 'element-plus'

  export default {
    name: "AddEmployee",
    props: {
      form: {
        type: Object,
        default() {
          return {
            name: '',
            sex: '男',
            phone: '',
            id: '',
            dept: '',
            post: '',
            status: '',
            entryDate: '2022-06-28',
            birth: '2000-01-01',
          }
        }
      },
      depts: {
        type: Array,
        default() {
          return []
        }
      },
      statusList: {
        type: Array,
        default() {
          return []
        }
      },
      dialogState: {
        type: Boolean,
        default() {
          return false;
        }
      },
      formLabelWidth: {
        type: String,
        default() {
          return "90px";
        }
      },
      dropLabelWidth: {
        type: String,
        default() {
          return "90px";
        }
      },
    },
    data() {
      return {
        mapping: {
          name: '姓名',
          sex: '性别',
          phone: '手机号码',
          id: '证件号码',
          dept: '部门',
          post: '岗位',
          status: '状态',
          entryDate: '入职时间',
          birth: '出生日期'
        }
      }
    },
    methods: {
      changeAddition() {
        this.$bus.emit('changeAdditionDialogState')
      },
      confirm(){
        let flag = true;
        for (const key in this.form) {
          if (this.form[key] === "") {
            flag = false;
            ElMessage('您的必填项 "' + this.mapping[key] + '" 没有填写哦');
            break;
          }
        }
        if (flag) {
          this.$bus.emit('confirmAddition');
        }
      },
    }
  }
</script>

<style scoped>

</style>